/*
The MIT License (MIT)

Copyright (c) 2013 Mike Dapiran, Brian May, Richard Pospesel, and Bert Wierenga

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software 
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#pragma once

#include "Hogshead.Common.h"
#include "Hogshead.Core.h"
#include "../DataStructures/ConstantBuffer/ConstantBuffer.h"
#include "../DataStructures/ConstantBuffer/ConstantBufferGroup.h"


#define GUIComponentH(className, humanReadableName)\
	GUIObjectH(className, humanReadableName)

#define GUIComponentCPP(className)\
	GUIObjectCPP(className)


struct ID3D11Buffer;

namespace Hogshead
{
	namespace DX11Rendering
	{
		class Technique;
		class Texture;
		
		struct GUIVertex
		{
			float Position[2];
			float UVx;
			float UVy;
		};

		/**
		* This class is the DX11Rendering interface for all IGUIObject components. This was created
		* so the GUIProcess can easily access the rendering data in one spot.
		*
		* @see IGUIObject
		* @see IComponent
		* @see Texture
		*
		* @author Ben Dapkiewicz
		*/
		class GUIComponent : public IGUIObject
		{
		friend class GUIProcess;
		friend class DX11Director;

		public:
			/**
			* Default Constructor; Does nothing.
			*/
			GUIComponent(void);

			/**
			* Destructor; Does nothing.
			*/
			~GUIComponent(void);

			/**
			* update method; Function that is called every frame on all components.
			*
			* @param in_gt The game time.
			*/
			virtual void update(const GameTimer& in_gt);

			/**
			* technique method; Returns a constant pointer to the Technique this IGUIObject uses.
			*/
			const Technique* technique() const;

		

			/**
			* constantBufferGroup method; Returns a constant reference to the ConstantBufferGroup this IGUIObject uses.
			*/
			const ConstantBufferGroup& constantBufferGroup() const;

			/**
			* vertex_buffer method; Returns a pointer to the vertex buffer.
			*/
			ID3D11Buffer* vertex_buffer();

			/**
			* component_position method; Returns the component's position.
			*/
			Vector2 component_position();

			/**
			* component_extents method; Returns the component's extents.
			*/
			Vector2 component_extents();

			/**
			* texture method; Returns the texture.
			*/
			const Texture* texture() const;

			int meshProcessHandle() {return _mesh_process_handle;}

		protected:
			int _mesh_process_handle;

			/**
			* constantBufferGroup method; Returns a reference to the ConstantBufferGroup this IGUIObject uses.
			*/			
			ConstantBufferGroup& constantBufferGroup();

			//the technique
			Technique* _technique;

			//the constant buffer group
			ConstantBufferGroup _constant_buffer_group;

			//the vertex buffer
			ID3D11Buffer* _vertex_buffer;

			//the position of the component
			Vector2 _component_position;
			//the extents of the component
			Vector2 _component_extents;

			//the texture to be rendered
			Texture* _texture;

		private:
			static void handle_constant_buffer_modifier(IMessageReceiver* self, IMessage* message);
		
		};
	}
}